package com.example.deliveryapplication.sql

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import com.example.deliveryapplication.entity.BearingType
import com.example.deliveryapplication.entity.Client
import com.example.deliveryapplication.entity.PlanWithPlanItem
import com.example.deliveryapplication.entity.TypeWithModel

@Dao
interface BearTypeDao {
    @Insert
    fun insertBearType(client: BearingType): Long
    @Query("select * from BearingType")
    fun loadAllBearType(): List<BearingType>
    @Query("select * from BearingType where id=:id")
    fun loadBearTypeById(id:String): BearingType
    @Delete
    fun deleteBearType(type:BearingType): Int
    @Query("SELECT `BearingType`.*, COUNT(BearingModel.id) AS itemCount FROM `BearingType` LEFT JOIN BearingModel ON `BearingModel`.typeId = BearingType.id WHERE `BearingType`.id=:id GROUP BY `BearingType`.id")
    fun getTypeWithModelCount(id:String): TypeWithModel
    @Update
    fun updateBearType(type:BearingType): Int
}